﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using Model;

namespace WebApplication2
{
    public partial class updateteacher : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                bind();
            }


        }

        private void bind()
        {
            int tno = Convert.ToInt32(Request.QueryString["tno"]);
            teacher tea = teacherinfoBLL.roomID(tno);
            tb_tno.Text = tea.tno.ToString();
            tb_pwd.Text = tea.password;
            tb_tname.Text = tea.tname;
            rb_sex.SelectedValue = tea.Sex.ToString();
            tb_tno.Enabled = false;
        }

        //实现修改页面
        protected void btn_update_Click(object sender, EventArgs e)
        {
            //string password, string name,string sex,int tno
            var cno = Convert.ToInt32(tb_tno.Text);
            var name = tb_tname.Text;
            var pwd = tb_pwd.Text;
            var sex = rb_sex.SelectedValue;
            if (teacherinfoBLL.update(pwd, name, sex, cno) > 0)
            {
                Response.Write("<script>alert('修改成功');location='teacherinfo.aspx'</script>");


            }
            else
            {
                Response.Write("<script>alert('修改失败')</script>");
            }
        }

        //返回
        protected void btn_back_Click(object sender, EventArgs e)
        {
            Response.Redirect("teacherinfo.aspx");
        }
    }
}